I have a DB that displays 2 lists... The first list consists of a standard set of enumerated values used for an attribute type called "Object Type". The second list gives the values that are used in the associated document's "Object Type" attribute. If these lists differ, the user has the ability to add and/or edit the values of the document's attribute to match the standards. I've been able to get the DB to work to show the changes the user wants, but am trying to figure out how to actually make the enumeration change. In the DXL Reference, I found the modify(attribute type) item, which contains the declaration:
AttrType modify(AttrType type,
string newName
[, string codes[ ],
int values[ ],...
Here is my current code:
void saveChanges(DB box) {
string arrNewValues[];
int arrNewNums[];
int arrColors[];
int n = 0;
AttrType at, atObjType;
string sErrMsg;
atObjType = find(current Module, "*Object Type");
for (n=0; n < noElems(dbeDocObjTypeList); n++) {
arrNewNums[n] = n+1;
arrNewValues[n] = getColumnValue(dbeDocObjTypeList, n, 0);
if (atObjType.colors[n] != null) {
arrColors[n] = atObjType.colors[n];
} else {
arrColors[n] = -1;
}
}
at = modify(atObjType, "*Object Type", arrNewNums, arrNewValues, arrColors, sErrMsg);
release dbObjTypeError;
dbObjTypeError = null;
}
I am getting an error (incorrect arguments) with the modify function call, but I'm not sure what it is looking for.
Chris
chrscote - Mon Jan 15 10:29:18 EST 2018 |
Re: Changing/adding values to enumerated type OK, I figured out one of the issues I had with my script, but now have another issue. First off, in my modify function, I had to swap the arrNewNums and arrNewValues variables and it would work for me. However, I now have another issue if I have to add an object type to the document's enumeration. I get the following error now: invalid index 7 to attribute type *Object Type This occurs when it gets to the line: if (atObjType.colors[n] != null) I know that there aren't 8 colors originally, which is why I tried to perform this check. So I don't know why it is giving me this error.
Chris |
Re: Changing/adding values to enumerated type Earlier discussion on modify has some working examples
|
Re: Changing/adding values to enumerated type PekkaMakinen - Tue Jan 16 00:58:09 EST 2018 Earlier discussion on modify has some working examples
Here is the code I'm now using. It isn't giving me an error, but the updated Object Type enumeration isn't being saved.
string arrNewValues[noElems(dbeDocObjTypeList)];
int arrNewNums[noElems(dbeObjTypeList)];
int arrColors[noElems(dbeObjTypeList)];
int n=0;
AttrType at, atObjType;
string sErrMsg;
atObjType = find(current Module, "*Object Type");
setRealColorOptionForTypes(true);
for (n=0; n<noElems(dbeDocObjTypeList); n++) {
arrNewNums[n] = n+1;
arrNewValues[n] = get(dbeDocObjTypeList, n);
if (n != noElems(dbeDocObjTypeList)-1) {
arrColors[n] = atObjType.colors[n];
} else {
arrColors[n] = -1;
}
}
at = modify(atObjType, "*Object Type", arrNewValues, arrNewNums, arrColors, sErrMsg);
release dbObjEnumError;
dbObjEnumError = null;
I thought I had the modify function written correctly since I wasn't getting an error, but when I check the module, any new items I add to the DocObjTypeList aren't getting added to the enumeration.
Chris |
Re: Changing/adding values to enumerated type chrscote - Thu Jan 18 08:57:40 EST 2018 Here is the code I'm now using. It isn't giving me an error, but the updated Object Type enumeration isn't being saved.
string arrNewValues[noElems(dbeDocObjTypeList)];
int arrNewNums[noElems(dbeObjTypeList)];
int arrColors[noElems(dbeObjTypeList)];
int n=0;
AttrType at, atObjType;
string sErrMsg;
atObjType = find(current Module, "*Object Type");
setRealColorOptionForTypes(true);
for (n=0; n<noElems(dbeDocObjTypeList); n++) {
arrNewNums[n] = n+1;
arrNewValues[n] = get(dbeDocObjTypeList, n);
if (n != noElems(dbeDocObjTypeList)-1) {
arrColors[n] = atObjType.colors[n];
} else {
arrColors[n] = -1;
}
}
at = modify(atObjType, "*Object Type", arrNewValues, arrNewNums, arrColors, sErrMsg);
release dbObjEnumError;
dbObjEnumError = null;
I thought I had the modify function written correctly since I wasn't getting an error, but when I check the module, any new items I add to the DocObjTypeList aren't getting added to the enumeration.
Chris I am still having an issue with saving the enumerated values. However, I now have a different problem. First off, I added one array arrMap below:
string arrNewValues[noElems(dbeDocObjTypeList)];
int arrNewNums[noElems(dbeDocObjTypeList)];
int arrColors[noElems(dbeDocObjTypeList)];
int arrMap[noElems(dbeDocObjTypeList)];
setRealColorOptionForTypes(true);
//Change the Object Type attribute to the new values
for (n=0; n<noElems(dbeDocObjTypeList); n++) {
arrNewNums[n] = n+1;
arrNewValues[n] = get(dbeDocObjTypeList, n);
if (n != noElems(dbeDocObjTypeList)-1) {
arrColors[n] = atObjType.colors[n];
} else {
arrColors[n] = 1;
}
}
atObjType = modify(atObjType, "*Object Type", arrNewValues, arrNewNums, arrColors, arrMap, sErr);
release dbObjEnumError;
dbObjEnumError = null;
The list of object types are getting saved now. However... when I save the list, I lose all of the attribute values for each object, even though the new values are added to the end of the list.
Chris |
Re: Changing/adding values to enumerated type chrscote - Mon Jan 29 14:44:49 EST 2018 I am still having an issue with saving the enumerated values. However, I now have a different problem. First off, I added one array arrMap below:
string arrNewValues[noElems(dbeDocObjTypeList)];
int arrNewNums[noElems(dbeDocObjTypeList)];
int arrColors[noElems(dbeDocObjTypeList)];
int arrMap[noElems(dbeDocObjTypeList)];
setRealColorOptionForTypes(true);
//Change the Object Type attribute to the new values
for (n=0; n<noElems(dbeDocObjTypeList); n++) {
arrNewNums[n] = n+1;
arrNewValues[n] = get(dbeDocObjTypeList, n);
if (n != noElems(dbeDocObjTypeList)-1) {
arrColors[n] = atObjType.colors[n];
} else {
arrColors[n] = 1;
}
}
atObjType = modify(atObjType, "*Object Type", arrNewValues, arrNewNums, arrColors, arrMap, sErr);
release dbObjEnumError;
dbObjEnumError = null;
The list of object types are getting saved now. However... when I save the list, I lose all of the attribute values for each object, even though the new values are added to the end of the list.
Chris In the past, I have only had luck doing this if I save the whole array set first (any that you care about, strings, values, colors etc) then add the new ones to the arrays before you do the modify.
Sara |
Re: Changing/adding values to enumerated type chrscote - Mon Jan 29 14:44:49 EST 2018 I am still having an issue with saving the enumerated values. However, I now have a different problem. First off, I added one array arrMap below:
string arrNewValues[noElems(dbeDocObjTypeList)];
int arrNewNums[noElems(dbeDocObjTypeList)];
int arrColors[noElems(dbeDocObjTypeList)];
int arrMap[noElems(dbeDocObjTypeList)];
setRealColorOptionForTypes(true);
//Change the Object Type attribute to the new values
for (n=0; n<noElems(dbeDocObjTypeList); n++) {
arrNewNums[n] = n+1;
arrNewValues[n] = get(dbeDocObjTypeList, n);
if (n != noElems(dbeDocObjTypeList)-1) {
arrColors[n] = atObjType.colors[n];
} else {
arrColors[n] = 1;
}
}
atObjType = modify(atObjType, "*Object Type", arrNewValues, arrNewNums, arrColors, arrMap, sErr);
release dbObjEnumError;
dbObjEnumError = null;
The list of object types are getting saved now. However... when I save the list, I lose all of the attribute values for each object, even though the new values are added to the end of the list.
Chris Well, you have defined the mapping array, but you do not use it. It has to contain values which compare the position of new / modified / deleted values in the enumerated list. Here as an example is a modified version of my toolbox script to add a new values to the "Risk" attribute in all modules in current folder. The old values are here for documentation, they are not used by the script. The example adds value "Insignificant" to the type for Risk attribute and the mapping array says that the previous three are the same as in the oldValues (i.e. zeroth position of newString is the same value as in oldStrings). and the last is added, so the mapping array index[3] is "-1" meaning that this value is not present in the oldStrings.
Now if we want to change an existing value to something else, then the mapping array just lists the same positions, but the new strings are different, e.g.
And if we want to delete a value, then the deleted value is "marked" in the mapping array by not having any value. Of course all of these arrays (values, colors, mapping) have to have the same number of values.
|